from django.contrib import admin
from goods.models import GoodsCategory,Goods,IndexPromotionBanner
from celery_tasks.tasks import generate_static_index_html
from django.core.cache import cache
# Register your models here.


class BaseAdmin(admin.ModelAdmin):
    def delete_model(self, request, obj):
        obj.delete()
        # 触发异步任务
        generate_static_index_html.delay()
        cache.delete('index_page_data')

        # 点击保存时，触发异步任务，生成静态主页到nginx

    def save_model(self, request, obj, form, change):
        # 保证可以实现数据存储，而不会被覆盖
        obj.save()
        # 触发异步任务
        generate_static_index_html.delay()
        cache.delete('index_page_data')

class IndexPromotionBannerAdmin(BaseAdmin):
    """IndexPromotionBanner模型类的管理类"""
    pass


class GoodsAdmin(BaseAdmin):
    """IndexPromotionBanner模型类的管理类"""

    pass

class GoodsCategoryAdmin(BaseAdmin):
    pass


admin.site.register(GoodsCategory,GoodsCategoryAdmin)
admin.site.register(Goods,GoodsAdmin)
admin.site.register(IndexPromotionBanner,IndexPromotionBannerAdmin)


